package com.shop.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqConfig {
    public static final String EMAIL_QUEUE_NAME = "email_queue";
    public static final String EMAIL_EXCHANGE_NAME = "email_exchange";
    public static final String EMAIL_ROUTING_KEY = "email_routing_key";

    @Bean(EMAIL_QUEUE_NAME)
    public Queue emailQueue() {
        return QueueBuilder.durable(EMAIL_QUEUE_NAME).build();
    }

    @Bean(EMAIL_EXCHANGE_NAME)
    public DirectExchange emailExchange() {
        return new DirectExchange(EMAIL_EXCHANGE_NAME);
    }

    @Bean
    public Binding emailBinding(Queue emailQueue, DirectExchange emailExchange) {
        return BindingBuilder.bind(emailQueue).to(emailExchange).with(EMAIL_ROUTING_KEY);
    }
}

